/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: EditSelfEvaluationView.java
 * Date: 04/02/2011
 */

package com.ingenius.sau.client.view;

import java.util.Date;
import java.util.List;

import com.extjs.gxt.ui.client.widget.form.DateField;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FormData;
import com.ingenius.sau.client.presenter.EditSelfEvaluationPresenter.EditSelfEvaluationDisplay;
import com.ingenius.sau.client.view.widgets.ListBox;
import com.ingenius.sau.shared.model.core.Scale;
import com.ingenius.sau.shared.model.guidelines.Guideline;
import com.ingenius.sau.shared.model.programs.AcademicProgram;

/**
 * Class <strong>EditSelfEvaluationView</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
public class EditSelfEvaluationView extends AbstractEditView implements
		EditSelfEvaluationDisplay {

	// UI Widgets
	private final TextField<String> textName;
	private final TextArea textDescription;
	private final ListBox comboProgram;
	private final ListBox comboGuidelines;
	private final ListBox comboState;
	private final ListBox comboScale;
	private final DateField startDateField;
	private final DateField deliveryDateField;

	// Constructor

	public EditSelfEvaluationView() {
		super();
		textName = new TextField<String>();
		textDescription = new TextArea();
		comboGuidelines = new ListBox();
		comboProgram = new ListBox();
		comboState = new ListBox();
		comboScale = new ListBox();
		startDateField = new DateField();
		deliveryDateField = new DateField();

		// TODO i18n
		setHeading("Edit Self-evaluation");
		setSize(500, 470);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.ingenius.sau.client.mvp.views.AbstractEditView#createComponents()
	 */
	@Override
	protected void createComponents() {
		// TODO i18n
		FormData formData = new FormData("-20");
		textName.setFieldLabel("Name");
		textName.setAllowBlank(false);
		textName.addPlugin(plugin);
		textName.setData("text", "Enter the evaluation name");
		textName.getMessages().setBlankText("Name is required");

		textDescription.setFieldLabel("Description");
		textDescription.setHeight(80);
		textDescription.setAllowBlank(false);
		textDescription.addPlugin(plugin);
		textDescription.setData("text", "Any description is fine...");
		textDescription.getMessages().setBlankText("Description is required");

		comboProgram.setFieldLabel("Program");
		comboProgram.setAllowBlank(false);
		comboProgram.setEditable(false);
		comboProgram.addPlugin(plugin);
		comboProgram.setData("text", "Select the academic program");
		comboProgram.getMessages().setBlankText("Program is required");

		comboGuidelines.setFieldLabel("Guidelines");
		comboGuidelines.setAllowBlank(false);
		comboGuidelines.setEditable(false);
		comboGuidelines.addPlugin(plugin);
		comboGuidelines.setData("text", "Select the guidelines");
		comboGuidelines.getMessages().setBlankText("Guidelines is required");

		comboState.setFieldLabel("State");
		comboState.setAllowBlank(false);
		comboState.setEditable(false);
		comboState.addPlugin(plugin);
		comboState.setData("text", "Select the process state");
		comboState.getMessages().setBlankText("State is required");

		comboScale.setFieldLabel("Scale");
		comboScale.setAllowBlank(false);
		comboScale.setEditable(false);
		comboScale.addPlugin(plugin);
		comboScale.setData("text", "Select the scale");
		comboScale.getMessages().setBlankText("Scale is required");

		startDateField.setFieldLabel("Start date");
		startDateField.setEditable(false);
		startDateField.setAllowBlank(false);
		startDateField.getMessages().setBlankText("Start date is required");

		deliveryDateField.setFieldLabel("Delivery date");
		deliveryDateField.setEditable(false);
		deliveryDateField.setAllowBlank(false);
		deliveryDateField.getMessages().setBlankText(
				"Delivery date is required");

		form.add(textName, formData);
		form.add(textDescription, formData);
		form.add(comboProgram, formData);
		form.add(comboGuidelines, formData);
		form.add(comboState, formData);
		form.add(comboScale, formData);
		form.add(startDateField, formData);
		form.add(deliveryDateField, formData);
	}

	@Override
	public String getName() {
		return textName.getValue();
	}

	@Override
	public void setName(String name) {
		textName.setValue(name);
	}

	@Override
	public String getDescription() {
		return textDescription.getValue();
	}

	@Override
	public void setDescription(String description) {
		textDescription.setValue(description);
	}

	@Override
	public String getAcademicProgramId() {
		return comboProgram.getSimpleValue();
	}

	@Override
	public void setAcademicProgramId(String programId) {
		comboProgram.setSimpleValue(programId);
	}

	@Override
	public void setAcademicPrograms(List<AcademicProgram> programs) {
		for (AcademicProgram program : programs) {
			comboProgram.add(program.getId(), program.getName());
		}
	}

	@Override
	public String getGuidelinesId() {
		return comboGuidelines.getSimpleValue();
	}

	@Override
	public void setGuidelinesId(String guidelinesId) {
		comboGuidelines.setSimpleValue(guidelinesId);
	}

	@Override
	public void setGuidelines(List<Guideline> guidelines) {
		for (Guideline guideline : guidelines) {
			comboGuidelines.add(guideline.getId(), guideline.toString());
		}
	}

	@Override
	public String getEvaluationState() {
		return comboState.getSimpleValue();
	}

	@Override
	public void setEvaluationState(String state) {
		comboState.setSimpleValue(state.toString());
	}

	@Override
	public void setEvaluationStates(List<String> states) {
		for (String state : states) {
			// TODO i18n 2º column
			comboState.add(state, state);
		}
	}

	@Override
	public String getScaleId() {
		return comboScale.getSimpleValue();
	}

	@Override
	public void setScaleId(String scaleId) {
		comboScale.setSimpleValue(scaleId.toString());
	}

	@Override
	public void setScales(List<Scale> scales) {
		for (Scale scale : scales) {
			comboScale.add(scale.getId(), scale.toString());
		}
	}

	@Override
	public Date getStartDate() {
		return startDateField.getValue();
	}

	@Override
	public void setStartDate(Date startDate) {
		startDateField.setValue(startDate);
	}

	@Override
	public Date getDeliveryDate() {
		return deliveryDateField.getValue();
	}

	@Override
	public void setDeliveryDate(Date deliveryDate) {
		deliveryDateField.setValue(deliveryDate);
	}

}
